<?php

namespace App\Http\Controllers\OpenShop\SiteLocation;

use App\Http\Controllers\BaseController;
use App\Service\SiteLocation\KpPartyService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class KpPartyController extends BaseController
{
    /**
     * 数据总览
     * @param Request $request
     * @return JsonResponse
     */
    public function overview(Request $request): JsonResponse
    {
        return $this->success(KpPartyService::overview());
    }


    /**
     * 列表
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function list(Request $request): JsonResponse
    {
        $rmsUserId = getRmsUserId();
        $pageNum   = (int)$request->get('pageNum', 1);
        $pageSize  = (int)$request->get('pageSize', 20);

        // 筛选参数
        $provinceCode      = (int)$request->get('provinceCode', 0);
        $cityCode          = (int)$request->get('cityCode', 0);
        $districtCode      = (int)$request->get('districtCode', 0);
        $companyType       = (string)$request->get('companyType', '');
        $company           = (string)$request->get('company', '');
        $userId            = (string)$request->get('userId', '');
        $phone             = (string)$request->get('phone', '');
        $wechatCode        = (string)$request->get('wechatCode', '');
        $wgName            = (string)$request->get('wgName', '');
        $followUpStartTime = (string)$request->get('followUpStartTime', '');
        $followUpEndTime   = (string)$request->get('followUpEndTime', '');
        $createdStartTime  = (string)$request->get('createdStartTime', '');
        $createdEndTime    = (string)$request->get('createdEndTime', '');

        return $this->success(
            KpPartyService::list($pageNum, $pageSize, $provinceCode, $cityCode, $districtCode, $companyType, $company, $userId, $phone, $wechatCode, $wgName, $rmsUserId, $followUpStartTime, $followUpEndTime, $createdStartTime, $createdEndTime)
        );
    }


    /**
     * 关联项目列表
     * @param Request $request
     * @return JsonResponse
     */
    public function relationProject(Request $request): JsonResponse
    {
        $pageNum  = (int)$request->get('pageNum', 1);
        $pageSize = (int)$request->get('pageSize', 20);
        $wgName   = (string)$request->get('wgName', '');

        return $this->success(KpPartyService::relationProject($pageNum, $pageSize, $wgName));
    }


}
